package syf.ArrayQueueDemo;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;



public class ArrayQueue {
    public static void main(String[] args) {
        String config="applicationContext.xml";
        ApplicationContext ac=new ClassPathXmlApplicationContext(config);
        Array1 array= (Array1) ac.getBean("array1");

        array.adddate();
        array.deldate();
        array.adddate();
        array.adddate();
        array.adddate();
        array.show();
    }
}
@Component
class Array1{
    private int max_size=3;
    private int rear=-1;
    private int front=-1;
    private int[] arr=new int[3];
    private int num=1;
    void adddate(){
        if (rear!=max_size-1) {
            rear++;
            arr[rear]=num++;
            System.out.println("插入了一个目标");
        }
        else {
            throw new RuntimeException("队列已满，无法储存数据");
        }
    }
    void deldate(){
        if (rear!=front){
            front++;
            System.out.println("删去了一个目标"+arr[front]);
            arr[front]=0;
        }
        else{
            throw new RuntimeException("队列已空，无法抛出数据");
        }
    }
    void show(){
        for (int x:arr)
            System.out.print(x+"  ");
    }
}
